import { RouteRecordRaw } from 'vue-router'

import AdminLayout from '@/layout/admin.vue'
import { useUserInfoStore } from '@/store'

import commonRoutes from '../common'
import { redirectPath } from '../help'
import activityManageRoutes from './activity-manage'
import algoServiceManageRoutes from './algo-service-manage'
import appCheckRoutes from './app-check'
import authManageRoutes from './auth-manage'
import caseManageRoutes from './case-manage'
import classManageRoutes from './class-manage'
import dataManageRoutes from './data-manage'
import drawingRecordManageRoutes from './drawing-record-manage'
import learningCaseManageRoutes from './learning-case-manage'
import learningTasksManageRoutes from './learning-tasks-manage'
import modelManageRoutes from './model-manage'
import roleManageRoutes from './role-manage'
import schoolOrganizationManageRoutes from './school-organization-manage'
import studentsAndClassesRoutes from './students-and-classes'
import sysLogRoutes from './sys-log'
import tagManageRoutes from './tag-manage'
import teacherManageRoutes from './teacher-manage'
// import userManageRoutes from './user-manage'

export const route: RouteRecordRaw = {
  path: '/admin',
  component: AdminLayout,
  meta: { title: '系统管理' },
  redirect: redirectPath,
  children: [
    ...algoServiceManageRoutes,
    ...classManageRoutes,
    ...caseManageRoutes,
    ...dataManageRoutes,
    ...modelManageRoutes,
    // ...userManageRoutes,
    ...roleManageRoutes,
    ...tagManageRoutes,
    ...learningTasksManageRoutes,
    ...sysLogRoutes,
    ...activityManageRoutes,
    ...appCheckRoutes,
    ...learningCaseManageRoutes,
    ...authManageRoutes,
    ...teacherManageRoutes,
    ...studentsAndClassesRoutes,
    ...drawingRecordManageRoutes,
    ...schoolOrganizationManageRoutes,
    ...commonRoutes
  ],
  beforeEnter: (to, from, next) => {
    const { userInfo } = useUserInfoStore()
    if (userInfo.roleType === 1) {
      // 如果 roleType 为 1，身份为学生,重定向到 '/'
      next('/')
    } else {
      // 否则，放行
      next()
    }
  }
}

export default route
